package com.iweb.blog.api;

import com.iweb.blog.vo.ArticleVo;
import com.iweb.blog.vo.param.PageParams;
import com.iweb.blog.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.iweb.blog.service.ArticleService;

import java.util.List;



@RestController
@RequestMapping("articles")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @PostMapping
    public Result articles(@RequestBody PageParams pageParams){
        List<ArticleVo> articles=articleService.listArticlesPage(pageParams);
        return Result.success(articles);
    }
    @PostMapping("hot")
    public Result hotArticles(){
        int limit=3;
        Result articleVoList=articleService.hotArticles(limit);
        return Result.success(articleVoList);
    }
    @PostMapping("new")
    public Result newArticles(){
        int limit=3;
        Result articleVoList=articleService.newArticles(limit);
        return Result.success(articleVoList);
    }

    @PostMapping("listArchives")
    public Result listArchives(){
        List<ArticleVo> articleList=articleService.listArchives();
        return Result.success(articleList);

    }
    @PostMapping("view/{id}")
    public Result findArticleById(@PathVariable("id") Long id) {
        Result articleVo = articleService.findArticleById(id);

        return Result.success(articleVo);
    }
}
